package com.zhou.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zhou.constant.MessageConstant;
import com.zhou.entity.PageResult;
import com.zhou.entity.QueryPageBean;
import com.zhou.entity.Result;
import com.zhou.pojo.Address;
import com.zhou.pojo.CheckItem;
import com.zhou.service.MapService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: Crazer
 * @Date: 2021/1/6 14:05
 * @version: 1.0.0
 * @Description: 地图管理
 */
@RestController
@RequestMapping("/map")
public class MapController {
    @Reference
    private MapService mapService;

    // 地图数据的分布查询
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return mapService.pageQuery(queryPageBean);
    }

    /**
     * 获取公司地址的详细信息
     *
     * @return
     */
    @PreAuthorize("hasAuthority('ADDRESS_QUERY')")
    @RequestMapping("/getAddressDetail")
    public Result getAddressDetail() {
        try {
            List<Address> list = mapService.getAddressDetail();
            return new Result(true, MessageConstant.GET_ADDRESS_SUCCESS, list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_ADDRESS_FAIL);
        }
    }

    /**
     * 删除地址
     *
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('ADDRESS_DELETE')")
    @RequestMapping("/delete")
    public Result delete(Integer id) {
        try {
            mapService.deleteById(id);
            return new Result(true, MessageConstant.DELETE_ADDRESS_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.DELETE_ADDRESS_FAIL);
        }
    }

    /**
     * 添加地址
     *
     * @param address
     * @return
     */
    @PreAuthorize("hasAuthority('ADDRESS_ADD')")
    @RequestMapping("add")
    public Result add(@RequestBody Address address) {
        try {
            mapService.add(address);
            return new Result(true, MessageConstant.ADD_ADDRESS_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ADD_ADDRESS_FAIL);
        }
    }
}
